GO
IF OBJECT_ID ( 'createUserFilter', 'P' ) IS NOT NULL 
    DROP PROCEDURE [dbo].[createUserFilter];
GO
CREATE PROCEDURE [dbo].[createUserFilter]
	@FilterName VARCHAR(40)
AS
BEGIN
	DECLARE @UserFilterId INT
    INSERT INTO [FILTER] ([NAME], [TABLE_NAME], [TYPE])
		VALUES(@FilterName, 'User', 'System')
	SET @UserFilterId = @@IDENTITY;
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'UserId', 'User', 'Id', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'UserLogin', 'User', 'Login', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'UserName', 'User', 'Name', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'UserSurname', 'User', 'Surname', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'UserMiddleName', 'User', 'MiddleName', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'UserEmail', 'User', 'Email', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'UserTelephon', 'User', 'Telephon', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'RoleName', 'Role', 'Name', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'ModuleStatus', 'Modules', 'Status', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@UserFilterId, 'ModuleMark', 'Modules', 'Mark', 'Text')
END
GO
